// 这是用来查询用户输入的js文件
const User = {
    //查询用户手机号
    queryUserTel(object) {
        return 'select * from user where tel = ' + object.userTel + ' '
    },
    //查询用户密码
    queryUserPwd(object) {
        return 'select * from user where (tel = ' + object.userTel + ') and (pwd=' + object.userPwd + ') '
    },
    //新增用户
    insertData(object) {
        let userTel = object.userTel
        let userPwd = object.userPwd || '123456'
            //引入token包
        const jwt = require('jsonwebtoken')
            //用户信息
        let payload = { tel: object.userTel }
            //口令
        let secret = 'songjie'
            //生成token
        let token = jwt.sign(payload, secret, {
                //token过期时间
                expiresIn: 600
            })
            //用户xxxxxx（初始用户名）
        let num = Math.floor(Math.random() * 100000)
            //----->
            // 默认密码为123456
        return 'insert into user (tel,pwd,imgUrl,nickName,token) values("' + userTel + '","' + userPwd + '","/images/my.jpg","用户' + num + '","' + token + '") '
    },
    //注册用户
    register(object) {
        //引入token包
        const jwt = require('jsonwebtoken')
            //用户信息
        let payload = { tel: object.userTel }
            //口令
        let secret = 'songjie'
            //生成token
        let token = jwt.sign(payload, secret, {
            //token过期时间
            expiresIn: 600
        })
        let num = Math.floor(Math.random() * 100000)
        return 'insert into user (tel,pwd,imgUrl,nickName,token) values ("' + object.userTel + '","' + object.userPwd + '","/images/my.jpg","用户' + num + '","' + token + '")'
    }
}

module.exports = User